package kr.co.dayve.site.management.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;

/**
 * Created by IntelliJ IDEA.
 * User: Yusung
 * Date: 12. 6. 12
 * Time: 오전 11:39
 * To change this template use File | Settings | File Templates.
 */
public class PropertiesUtil extends PropertyPlaceholderConfigurer {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);

    private Map propertiesMap;

    public void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException {

        super.processProperties(beanFactory, props);
        propertiesMap = new HashMap<String, String>();

        for (Object key : props.keySet()) {

            String keyStr = key.toString();
            propertiesMap.put(keyStr, parseStringValue(props.getProperty(keyStr), props, new HashSet()));

        }
    }

    public String getProperty(String name) {

        logger.info("getProperty");
        logger.info("property name : {}", name);


        return (String)propertiesMap.get(name);
    }
}